package com.ququ.syb.entrance.service;

import com.ququ.common.result.Result;
import com.ququ.common.result.ResultJson;
import com.ququ.syb.common.constant.EncryptTypeConstant;
import com.ququ.syb.common.constant.ResultStatusConstant;
import com.ququ.syb.common.pojo.AccountChannelBalance;
import com.ququ.syb.entrance.fegin.BalanceFegin;
import com.ququ.syb.entrance.po.RequestData;
import com.ququ.syb.entrance.vo.SybResult;
import com.ququ.syb.entrance.vo.SybResultData;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class BalanceService {
    @Autowired
    private BalanceFegin balanceFegin;
    @Autowired
    private SecurityService securityService;

    private Logger logger = LoggerFactory.getLogger(BalanceService.class);

    public SybResult listAccountChannelBalance(RequestData<String> requestData){
        if (requestData.getEncryptType() != EncryptTypeConstant.AES)
            return new SybResult(-1,"加密方式不正确",securityService.sign(new SybResultData(requestData.getAccountid(),""),requestData.getAppcode()),requestData.getAccountid());
        Map<String,Object> dataMap = securityService.getParametersMap(requestData);
        logger.debug("请求参数:{}",dataMap);
        Result<List<AccountChannelBalance>> balanceListResult = balanceFegin.listAccountChannelBalance(requestData.getAccountid());
        if (balanceListResult.getStatus() != ResultStatusConstant.SUCCESS)
            return new SybResult(balanceListResult.getStatus(),balanceListResult.getMsg(),securityService.sign(new SybResultData(requestData.getAccountid(),""),requestData.getAppcode()),requestData.getAccountid());
        else
            return securityService.buildSybResult(balanceListResult.getData(),requestData);
    }

}
